import java.util.EmptyStackException;
import java.util.Stack;

/**
 * 
 * @author 魏康威
 *
 */
class MyQueue {
    private Stack<Integer> stackIn = new Stack<Integer>();
    private Stack<Integer> stackOut = new Stack<Integer>();
    
    public void push(int node) {
    	while(!stackOut.isEmpty()) {
    		stackIn.push(stackOut.pop());
    	}
        stackIn.push(node);
    }

    public int pop() {
    	while(!stackIn.isEmpty()) {
    		stackOut.push(stackIn.pop());
    	}
    	if(!stackOut.isEmpty()) {
    		return stackOut.pop();
    	}
    	throw new EmptyStackException();
    }
	
    public int peek() {
    	while(!stackIn.isEmpty()) {
    		stackOut.push(stackIn.pop());
    	}
    	if(!stackOut.isEmpty()) {
    		return stackOut.peek();
    	}
    	throw new EmptyStackException();
    }
    
    public boolean empty() {
    	if(!stackIn.isEmpty() || !stackOut.isEmpty()) {
    		return false;
    	}
    	return true;
    }
    
    @Override
    public String toString() {
    	return "stackIn:" + stackIn + " stackOut:" + stackOut.toString();
    }
}

public class StackQueue {

	public static void main(String[] args) {
		MyQueue myQueue = new MyQueue();
		myQueue.push(1);
		myQueue.push(2);
		myQueue.push(3);
		
		int peek = myQueue.peek();
		System.out.println("peek = " + peek);
		
		int pop = myQueue.pop();
		System.out.println("pop = " + pop);
		
		int pop2 = myQueue.pop();
		System.out.println("pop2 = " + pop2);
		
		boolean isEmpty = myQueue.empty();
		System.out.println("empty:" + isEmpty);
		
		int pop3 = myQueue.pop();
		System.out.println("pop3 = " + pop3);
		
		isEmpty = myQueue.empty();
		System.out.println("empty:" + isEmpty);
	}
}
